package com.maven.springaop.demos.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
@Aspect
public class AspectDemo {
    // 切点表达式 太冗余，提炼出来
    // 当然，也可以在别的类中进行使用
    // 类外使用 ：全限定类名. 方法名
    @Pointcut("execution(* com.maven.springaop.demos.controller.*.*(..))")
    public void pc() {}



    @Around("pc()")
    public Object doAspect(ProceedingJoinPoint pj) throws Throwable {
        log.info("doAspect : 方法执行前");
        Object result = null;
        result = pj.proceed();
        log.info("doAspect : 方法执行后");
        return result;
    }

    @Before("pc()")
    public void doBefore() {
        log.info("doBefore 执行");
    }

    @After("execution(* com.maven.springaop.demos.controller.*.*(..))")
    public void doAfter() {
        log.info("doAfter 执行");
    }

   @AfterReturning("execution(* com.maven.springaop.demos.controller.*.*(..))")
    public void doAfterReturning() {
        log.info("doAfterReturning 执行");
    }

     @AfterThrowing("execution(* com.maven.springaop.demos.controller.*.*(..))")
    public void doAfterThrowing() {
        log.info("doAfterThrowing 执行");
    }


}
